package com.http;

import java.util.ArrayList;

import org.json.JSONArray;

import android.os.AsyncTask;

import com.android.ocean.util.net.ErrorCode;
import com.android.ocean.util.net.NetConUtil;
import com.android.ocean.util.net.ResEntity;
import com.common.method.CommonData;
import com.common.method.ServerPath;
import com.modle.BlackStruct;
import com.util.JsonUtil;

/**
 * 
 * @ClassName:BlackListTask
 * @Description:TODO黑名单
 * @author zhuw
 * @date 2013-9-1 上午10:40:33
 */
public class BlackListTask extends AsyncTask<String, Void, ResultBlackList> {
	public static interface CallBack extends NetWorkCallBack {
		public abstract void procBlackListData(ArrayList<BlackStruct> dataList);

	}

	CallBack callback;

	public BlackListTask(CallBack callback) {
		super();
		this.callback = callback;
	}

	@Override
	protected ResultBlackList doInBackground(String... params) {
		ResultBlackList data = null;
		try {
			ResEntity re = null;
			String type=params[0];
		
				re = NetConUtil.sendGetRequestEntity(ServerPath.BLACK_LIST_PATH+params[0]);
			
			if (re.code == ResEntity.S_OK) {
				data = new ResultBlackList(CommonData.H_FLAG_SUCCESS, null,
						JsonUtil.parseBlackList(new JSONArray(re.jsonStr)));
			} else if (re.code == ResEntity.S_FAILED) {

				data = new ResultBlackList(CommonData.H_FLAG_ERROR, "code:"
						+ re.code + "    " + re.jsonStr, null);

			} else {
				data = new ResultBlackList(CommonData.H_FLAG_ERROR, "code:"
						+ re.code + ErrorCode.ERROR_MSG, null);
			}
		} catch (Exception e) {
			data = new ResultBlackList(CommonData.H_FLAG_ERROR,
					ErrorCode.ERROR_MSG, null);
			e.printStackTrace();

		}
		return data;
	}

	@Override
	protected void onPostExecute(ResultBlackList result) {
		if (result.flag == CommonData.H_FLAG_SUCCESS) {
			callback.procBlackListData(result.dataList);

		} else {
			callback.procError(result.msg);
		}

	}
}
